package cn.openea.perpartner.cms.web.controller;


import cn.openea.perpartner.cms.factory.UserContext;
import cn.openea.perpartner.cms.web.service.ICmsSalesAssistantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.openea.perpartner.cms.web.entity.CmsSales;
import cn.openea.perpartner.cms.web.entity.CmsSalesAssistant;
import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 销售助理列表(CmsSalesAssistant)表控制层
 *
 * @author Weird077
 * @since 2022-09-04 08:51:36
 */
@Api(tags = "销售管理")
@RestController
@RequestMapping("sales/assistant")
public class CmsSalesAssistantController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private ICmsSalesAssistantService salesAssistantService;

    @ApiOperation("助理管理")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo selectAll(String userId, String searchStr) {
        List<CmsSalesAssistant> list = salesAssistantService.selectAll(userId,searchStr);
        return getDataTable(list);
    }
    @ApiOperation("关联销售")
    @PostMapping("/salesList")
    @ResponseBody
    public TableDataInfo selectSalesList(String openeaId,String searchStr) {
        List<CmsSales> list = salesAssistantService.selectSalesList(openeaId,searchStr);
        return getDataTable(list);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("助理信息")
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(salesAssistantService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param salesAssistant 实体对象
     * @return 新增结果
     */
    @ApiOperation("添加助理")
    @PostMapping("/add")
    public AjaxResult insert(@RequestBody CmsSalesAssistant salesAssistant) {
        return salesAssistantService.insert(salesAssistant)?success():error();
    }

    /**
     * 修改数据
     * @param salesAssistant 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改助理")
    @PutMapping("/edit")
    public AjaxResult update(@RequestBody CmsSalesAssistant salesAssistant) {
        salesAssistant.setUpdateUser(UserContext.getUserId());
        return salesAssistantService.updateById(salesAssistant)?success():error();
    }

    /**
     * 删除数据
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("删除助理")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> idList) {
        return salesAssistantService.removeBatch(idList)?success():error();
    }


}

